#! /usr/bin/env python
import argparse, os, sys, json
from nextapp.ont_qc import run_ontqc


def ontqc_option(parser_ontqc):
    parser_ontqc.add_argument('-t', '--type', required=True, choices=('cell', 'list', 'report'), help='Tools of this function')
    parser_ontqc.add_argument('-i', '--input', required=True, help='''
        1. input directory of single cell for "-t cell", eg "/export/ont/20180413-NPL0035-K1"
        2. input file contains the multi-cell directory list for "-t list", eg "/export/ont/cell_list.txt"
        3. input directory of ONT root path which contains machine NO. for "-t report", eg "/export/ont/cell_list.txt"
    ''')
    ##### CELL && LIST PARAMETER #####
    parser_ontqc.add_argument('-th', '--thread', type=int, default=1, help='Thread number, Only -t cell, list')
    parser_ontqc.add_argument('-qc', '--qscore_cutoff', default=7.0, type=float,
                              help='The cutoff value of high quality score, Only -t cell, list')
    parser_ontqc.add_argument('-ds', '--distribution_step', type=int, default=5 * 1000,
                              help='The interval step of reads length distribution statistics, Only -t cell, list')
    parser_ontqc.add_argument('-de', '--distribution_endpoint', type=int, default=300 * 1000,
                              help='The length endpoint of of reads length distribution statistics, Only -t cell, list'
                              )
    ##### SAMPLE PARAMETER #####
    parser_ontqc.add_argument('-o', '--outdir', help='Output directory, Only -t report')
    parser_ontqc.add_argument('-p', '--project', help='Project name, Only -t report')
    parser_ontqc.add_argument('-s', '--sample', help='Sample name, Only -t report')
    parser_ontqc.add_argument('-wp', '--writer', default='甘军', help='Report writer, Only -t report')
    parser_ontqc.add_argument('-vp', '--verifier', default='秦建虎', help='Report verifier, Only -t report')
    parser_ontqc.set_defaults(function=run_ontqc)


if __name__ == '__main__':
    if len(sys.argv) == 1:
        sys.stderr.write('Usage: %s [-h]\n\n' % os.path.basename(sys.argv[0]))
        sys.exit()
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description='''
        NextOmics Copyright(c) 2018.
        Author: Ying Zhu
        '''
    )
    sub_parsers = parser.add_subparsers(help='Command list')
    parser_ontqc = sub_parsers.add_parser('ontqc', help='Quality Control and Filter and Statistics of ONT sequencing data')
    ontqc_option(parser_ontqc)
    args = parser.parse_args()
    args.function(args)
